package com.swsc.solarverse.dao.mapper.forward;

import com.swsc.solarverse.common.mybatis.BasePlusMapper;
import com.swsc.solarverse.dao.entity.forward.ForwardEnvironmentalMonitorDataDO;
import org.apache.ibatis.annotations.Mapper;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author AutoGenerator
 * @since 2022-08-24
 */
@Mapper
public interface ForwardEnvironmentalMonitorDataMapper extends BasePlusMapper<ForwardEnvironmentalMonitorDataDO> {
    /**
     * 批量插入环境监测仪数据
     * 不存在插入, 存在则更新
     *
     * @param list
     * @return
     */
    @org.apache.ibatis.annotations.Insert(value = {
            "<script>",
            "INSERT INTO solar_forward_environmental_monitor_data (`id`, `tenant_no`, `organ_no`, `device_id`, `device_name`, `wind_speed`, `temperature`, `total_radiation_1`, `acc_total_radiation_1`, `total_radiation_2`, `acc_total_radiation_2`, `scattered_radiation`, `acc_scattered_radiation`, `direct_radiation`, `acc_direct_radiation`, `data_time`, `create_time`) VALUES ",
            "<foreach collection='list' item='item' index='index' separator=','>",
            "(#{item.id}, #{item.tenantNo}, #{item.organNo}, #{item.deviceId}, #{item.deviceName}, #{item.windSpeed}, #{item.temperature}, #{item.totalRadiation1}, #{item.accTotalRadiation1}, #{item.totalRadiation2}, #{item.accTotalRadiation2}, #{item.scatteredRadiation}, #{item.accScatteredRadiation}, #{item.directRadiation}, #{item.accDirectRadiation},  #{item.dataTime}, #{item.createTime})",
            "</foreach>",
            " ON DUPLICATE KEY UPDATE ",
            "device_name = VALUES (device_name), wind_speed = VALUES (wind_speed), temperature = VALUES (temperature), ",
            "total_radiation_1 = VALUES (total_radiation_1), acc_total_radiation_1 = VALUES (acc_total_radiation_1), ",
            "total_radiation_2 = VALUES (total_radiation_2), acc_total_radiation_2 = VALUES (acc_total_radiation_2), ",
            "scattered_radiation = VALUES (scattered_radiation), acc_scattered_radiation = VALUES (acc_scattered_radiation), ",
            "direct_radiation = VALUES (direct_radiation), acc_direct_radiation = VALUES (acc_direct_radiation), ",
            "data_time = VALUES (data_time)",
//            "<trim prefix='' suffixOverrides=','>",
//            "<foreach collection='list'  item='item' index='index'  separator=','>",
//            "tenant_no = VALUES (tenant_no), organ_no = VALUES (organ_no), device_id VALUES (device_id) ",
//                    "<if test='item.deviceName != null and item.deviceName != ''>device_name = VALUES(device_name),</if>",
//            "</foreach>",
//            "</trim>",
            "</script>"
    })
    int insertOrUpdateBatch(java.util.List<ForwardEnvironmentalMonitorDataDO> list);
}
